package SecondeStage.IO.Reader_Writer;

import java.io.FileWriter;
import java.io.IOException;

public class FileWriter_ {
    public static void main(String[] args) {
        String filePath ="D:\\Java\\JavaProject\\note.txt";
        FileWriter fileWriter=null;
        char[] chars ={'a','b','c'};
        try {
            fileWriter = new FileWriter(filePath);
            fileWriter.write('H');
            fileWriter.write(chars);
            fileWriter.write("韩顺平教育".toCharArray(),0,3);
            fileWriter.write(" 你好北京~");
            fileWriter.write("上海天津",0,2);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(fileWriter!=null){
                try {
                    // FileWriter使用后，必须要关闭(close)或刷新(flush)，否则写入不到指定文件
                    fileWriter.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
